package ddbs;

import java.io.IOException;
import java.util.*;

public class test {
    public static String sqls[] = new String[8];

    private static void init() {
        sqls[0] = "select * from Customer";
        sqls[1] = "select publisher.name from Publisher";
        sqls[2] = "select Book.title from Book where copies > 5000";
        sqls[3] = "select customer_id, quantity from Orders where quantity < 8";
        sqls[4] = "select Book.title,Book.copies, Publisher.name, Publisher.nation"
                + " from	Book,Publisher"
                + " where	Book.publisher_id=Publisher.id and"
                + "		Publisher.nation='USA' and" + "		Book.copies > 1000";
        sqls[5] = "select	Customer.name,Orders.quantity"
                + " from	Customer,Orders"
                + " where	Customer.id=Orders.customer_id";
        sqls[6] = "select	Customer.name ,Orders.quantity,Book.title"
                + " from 		Customer,Orders,Book"
                + " where 		Customer.id=Orders.customer_id and "
                + " 			Book.id=Orders.book_id and " + "			Customer.rank=1 and"
                + "			Book.copies>5000";
    }

    public static void testGuiHandleSQL() throws IOException {
        Ddbs ddbs = new Ddbs("ddbs0.ini");
        ddbs.start();
        for (int i = 0; i < 1; ++i) {
            System.out
                    .println("START----------------------------------------------------");
            Data d = ddbs.gui.handleSQL("select Customer.name from Customer where Customer.rank>1");
            StringBuffer html = d.generateHtmlTable();
            System.out
                    .println("END--------------------------------------------------------");
        }
    }

    public static void testSQLParse() throws IOException {
        Ddbs ddbs0 = new Ddbs("ddbs0.ini");
        for (int i = 6; i < 7; ++i) {
            System.out
                    .println("START"+i+"--------------------------------------------------------");
            Workload wkload = new Workload(ddbs0.mgr, "select Book.title,Orders.quantity,Book.id,Orders.customer_id,Orders.book_id from Book,Orders where Book.id=Orders.book_id and Book.copies>5000");
            wkload.show();
            System.out
                    .println("END"+i+"---------------------------------------------------------");
        }
    }

    public static void main(String args[]) {
        try {
            init();
            //testGuiHandleSQL();
            testSQLParse();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
